#include "np_manager.h"

#include "../sleipner_config.h"

#ifdef _PLATFORM_IOS
#include "c_np_manager.h"
#endif

#ifdef _PLATFORM_ANDROID
#include "SDL2/src/core/android/SDL_android.h"
#include "android/sleipner_android.h"
#endif

#include "gameflow/game_flow_manager.h"


static void     OnDashBoardShowCB(void);
static void     OnDashBoardHideCB(void);

NextPeerManager&          NextPeerManager::Instance()
{
    static NextPeerManager	Inst;
	return Inst;
}

NextPeerManager::NextPeerManager() 
{
    
}

void	NextPeerManager::Init(const std::string& Key)
{
#ifdef _PLATFORM_ANDROID
	Android_JNI_SendMessage(FUNC_NEXTPEER_Init, 0);
#endif
    
#ifdef _PLATFORM_IOS
   
    CInitNextPeer(Key.c_str(),
                  (OnCDashBoardShowCB)OnDashBoardShowCB,
                  (OnCDashBoardHideCB)OnDashBoardHideCB);
#endif
    
}

void	NextPeerManager::ReportForfeitForCurrentTournament()
{
#ifdef _PLATFORM_IOS
	CReportForfeitForCurrentTournament();
#endif

#ifdef _PLATFORM_ANDROID
    Android_JNI_SendMessage(FUNC_NEXTPEER_ReportForfeitForCurrentTournament , 0);
#endif
}

void	NextPeerManager::ReportControlledTournamentOver(int Score)
{
#ifdef _PLATFORM_IOS
	CReportControlledTournamentOver(Score);
#endif

#ifdef _PLATFORM_ANDROID
	Android_JNI_SendMessage(FUNC_NEXTPEER_ReportControlledTournamentOver, Score);
#endif
}

void    NextPeerManager::ReportScore(int Score)
{
#ifdef _PLATFORM_IOS
    CReportScoreNextPeer(Score);
#endif

#ifdef _PLATFORM_ANDROID
    Android_JNI_SendMessage(FUNC_NEXTPEER_ReportScore, Score);
#endif
   
}

void NextPeerManager::LaunchDashboard()
{
#ifdef _PLATFORM_IOS
    CLaunchDashboardNextPeer();
#endif

#ifdef _PLATFORM_ANDROID
   Android_JNI_SendMessage(FUNC_NEXTPEER_LaunchDashboard, 0);
#endif
}

void NextPeerManager::ShutDown()
{

#ifdef _PLATFORM_IOS
    CShutDownNextPeer();
#endif

#ifdef _PLATFORM_ANDROID
    Android_JNI_SendMessage(FUNC_NEXTPEER_ShutDown,0);
#endif

}

void	NextPeerManager::SetCurrentTournament(int LevelNum)
{


#ifdef _PLATFORM_ANDROID
	   Android_JNI_SendMessage(FUNC_NEXTPEER_SetCurrentTournament,LevelNum);
#endif
}


void	NextPeerManager::SetCurrentTournament(const std::string& LevelID)
{
#ifdef _PLATFORM_IOS
    CSetCurrentTournament(LevelID.c_str());
#endif
}

void    NextPeerManager::OnDashBoardShow()
{
    gameflow::GameFlowManager::Instance().SetIsPause(true);
}

void    NextPeerManager::OnDashBoardHide()
{
    gameflow::GameFlowManager::Instance().SetIsPause(false);
}

void     OnDashBoardShowCB()
{
    NextPeerManager::Instance().OnDashBoardShow();
}


void     OnDashBoardHideCB()
{
    NextPeerManager::Instance().OnDashBoardHide();
}

